package com.rpp.controller;

import com.rpp.service.HelloService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description
 * @Author rpp
 * @Date 2020/8/16 7:52 下午
 */
@RestController
@RequestMapping(value = "/test")
public class TestController {

    private static final Integer MAX_POOL_SIZE = 3000;

    private static final ExecutorService threadPool = Executors.newFixedThreadPool(MAX_POOL_SIZE);

    @DubboReference
    private HelloService helloService;

    @RequestMapping(value = "/hello")
    public String sayHello(String name) {
        return helloService.sayHello(name);
    }

    /**
     * 测试dubbo接口方法性能
     *
     * @return
     */
    @RequestMapping(value = "/tp")
    public String test() {

        int i = 0;
        while (i < MAX_POOL_SIZE) {
            i++;
            threadPool.execute(() -> helloService.methodA());
            threadPool.execute(() -> helloService.methodB());
            threadPool.execute(() -> helloService.methodC());
        }
        return "test";
    }

}
